﻿using AutoMapper;
using MediatR;
using PersonnelManagement.Application.Command.ClientCommand;
using PersonnelManagement.Infrstructre.Interface;

namespace PersonnelManagement.Application.CommandHandler.ClientCommandHandlers
{
    public class ClientDelCommandHandlers : IRequestHandler<ClientDelCommand, int>
    {
        IClientRepository cRep;
        IMapper mapper;
public ClientDelCommandHandlers(IClientRepository cRep, IMapper mapper)
        {
            this.cRep = cRep;
            this.mapper = mapper;
        }
        public async Task<int> Handle(ClientDelCommand request, CancellationToken cancellationToken)
        {
            var list = (await cRep.Getall()).Where(x=>request.ClientId.Contains(x.ClientId)).ToList();
            foreach (var item in list)
            {
                item.IsDel = true;
                item.DelName = request.DelName;
                item.DelTime = DateTime.Now;
                await cRep.UpdateAsymc(item);
            }
            return 1;
        }
    }
}
